<!DOCTYPE html>
<html>
<head>
    <title>Preview Display</title>
    <meta charset="UTF-8">
    <style>
        html,
        body {
            padding: 0px;
            margin: 0px;
        }

        body {
            background: #000 url(./assets/兴达八厂/背景兴达.jpg) no-repeat left top;
            background-size: 100%;
        }
    </style>
    <script src='../custom/libs/echarts.js'></script>
    <script src='../libs/core/ht.js'></script>
    <script src='../libs/plugin/ht-vector.js'></script>
    <script src='../conf/dateTime.js'></script>
    <script src='../libs/jquery-3.4.1.min.js'></script>
    <script src="../conf/confURL.js"></script>
    <script>
        dataModel = new ht.DataModel();
        graphView = new ht.graph.GraphView(dataModel);
        // 九厂编码
        let deptCode = "XD1113";
        var url = domain + "/HT_DATA_EIGHT.getGlobalStatistics.do";
        var H = [];
        var Chart = [];
        var warn = [];
        let button = [];
        let pie1;
        let pie2;
        let lostpie;
        var onecar;
        var twocar1;
        var twocar2;
        var threecar;
        var fourcar;
        var OEE;
        var MTBF;
        var MTTR;
        var data = [];
        function init() {
            graphView.addToDOM();
            ht.Default.xhrLoad('displays/智慧兴达/兴达八厂/设备监控/device_nineFactory.json', function (text) {
                var json = ht.Default.parse(text);
                if (json.title) document.title = json.title;
                dataModel.deserialize(json);
                graphView.fitContent(true);
                tag();
                getEQGZTTSTJ(deptCode);
                getEQWXCBTJ(deptCode);
                getEQGZLTJ(deptCode);
                getEQDPNHTJ(deptCode);
                getMAP(deptCode);
                getRETURN(deptCode);
                getEQWXXHQKTJ(deptCode, "XD111203");
                getEQWXXHQKTJ(deptCode, "XD111204");
                getEQOEEMTBFRTJ(deptCode, "OEE");
            });
            //页面时间刷新
            setInterval(function () {
                let dateTime = dataModel.getDataByTag("dateTime");
                let time = updateTime();
                dateTime.a('time', time);
            }, 1000);
            //车间维护维修数据自动切换
            var time1 =
                setInterval(function () {
                    if (button[0].a("visible") === true) {
                        cut1(twocar1);
                        // 下一个要选中的
                        button[1].a("visible", true);
                        for (let i = 0; i < 6 && i != 1; i++) {
                            button[i].a("visible", false)
                        }
                    } else if (button[1].a("visible") === true) {
                        cut1(twocar2);
                        button[2].a("visible", true);
                        for (let i = 0; i < 6 && i != 2; i++) {
                            button[i].a("visible", false)
                        }
                    } else if (button[2].a("visible") === true) {
                        cut1(threecar);
                        button[3].a("visible", true);
                        for (let i = 0; i < 6 && i != 3; i++) {
                            button[i].a("visible", false)
                        }
                    }else if (button[3].a("visible") === true) {
                        cut1(fourcar);
                        button[4].a("visible", true);
                        for (let i = 0; i < 6 && i != 4; i++) {
                            button[i].a("visible", false)
                        }
                    }else if (button[4].a("visible") === true) {
                        cut1(onecar);
                        button[0].a("visible", true);
                        for (let i = 1; i < 6 ; i++) {
                            button[i].a("visible", false)
                        }
                    }
                }, 1000 * 5);
            //设备OEE/MTBF/MTTR数据自动切换
            var time2 =
                setInterval(function () { //饼图定时切换
                    if (button[5].a("visible") === true) {
                        cut2(MTBF);
                        button[5].a("visible", false);
                        button[6].a("visible", true);
                        button[7].a("visible", false);
                    } else if (button[6].a("visible") === true) {
                        cut2(MTTR);
                        button[5].a("visible", false);
                        button[6].a("visible", false);
                        button[7].a("visible", true);
                    } else if (button[7].a("visible") === true) {
                        cut2(OEE);
                        button[5].a("visible", true);
                        button[6].a("visible", false);
                        button[7].a("visible", false);
                    }
                }, 1000 * 5);
            //监听事件点击实现报表切换
            graphView.addInteractorListener(function (e) {
                if (e.kind === 'clickData') {
                    // 维修情况按钮标签
                    if (e.data._tag === 'button1') {
                        // 饼图数据改变
                        cut1(onecar);
                        button[0].a("visible", true);
                        for (let i = 1; i < 5; i++) {
                            button[i].a("visible", false)
                        }
                        clearInterval(time1);
                    }
                    else if (e.data._tag === 'button2') {
                        cut1(twocar1);
                        for (let i = 0; i < 5; i++) {
                           button[i].a("visible", false)
                        }
                        button[1].a("visible", true);
                        clearInterval(time1);
                    }
                    else if (e.data._tag === 'button3') {
                        cut1(twocar2);
                        for (let i = 0; i < 5; i++) {
                            button[i].a("visible", false)
                        }
                        button[2].a("visible", true);
                        clearInterval(time1);
                    }else if (e.data._tag === 'button4') {
                        // 饼图数据改变
                        cut1(threecar);
                        for (let i = 0; i < 5; i++) {
                            button[i].a("visible", false)
                        }
                        button[3].a("visible", true);
                        clearInterval(time1);
                    }
                    else if (e.data._tag === 'button5') {
                        cut1(fourcar);
                        for (let i = 0; i < 5; i++) {
                            button[i].a("visible", false)
                        }
                        button[4].a("visible", true);
                        clearInterval(time1);
                    }
                    // oee
                    else if (e.data._tag === 'button6') {
                        cut2(OEE);
                        button[5].a("visible", true);
                        button[6].a("visible", false);
                        button[7].a("visible", false);
                        clearInterval(time2);
                    }
                    else if (e.data._tag === 'button7') {
                        cut2(MTBF);
                        button[6].a("visible", true);
                        button[5].a("visible", false);
                        button[7].a("visible", false);
                        clearInterval(time2);
                    }
                    else if (e.data._tag === 'button8') {
                        cut2(MTTR);
                        button[7].a("visible", true);
                        button[5].a("visible", false);
                        button[6].a("visible", false);
                        clearInterval(time2);
                    }
                }
            });
        }
        function tag() {
            pie1 = dataModel.getDataByTag("pie1");
            pie2 = dataModel.getDataByTag("pie2");
            for (let i = 1; i < 5; i++) {
                Chart.push(dataModel.getDataByTag("Chart" + i))
            }
            for (let i = 1; i < 7; i++) {
                H.push(dataModel.getDataByTag("H" + i))
            }
            for (let i = 1; i < 7; i++) {
                warn.push(dataModel.getDataByTag("warn" + i))
            }
            for (let i = 1; i < 9; i++) {
                button.push(dataModel.getDataByTag("button" + i))
            }
            // 九厂一车间
            onecar = getEQWXXHQKTJ(deptCode, "XD111303");
            twocar1 = getEQWXXHQKTJ(deptCode, "XD11130401");
            twocar2 = getEQWXXHQKTJ(deptCode, "XD11130402");
            threecar = getEQWXXHQKTJ(deptCode, "XD111305");
            fourcar = getEQWXXHQKTJ(deptCode, "XD111306");

            OEE = getEQOEEMTBFRTJ(deptCode, "OEE");
            MTBF = getEQOEEMTBFRTJ(deptCode, "MTBF");
            MTTR = getEQOEEMTBFRTJ(deptCode, "MTTR");
        }
        // 九厂设备维修/维护情况 饼图
        function cut1(repData) {
            if(repData.data != null && repData.data != undefined && repData.data != ''){
            pie1.a("name1", repData.data[0].name);
            pie1.a("name2", repData.data[1].name);
            pie1.a("name3", repData.data[2].name);
            pie1.a("value1", repData.data[0].value);
            pie1.a("value2", repData.data[1].value);
            pie1.a("value3", repData.data[2].value);
            pie2.a("name1", repData.data1[0].name);
            pie2.a("name2", repData.data1[1].name);
            pie2.a("value1", repData.data1[0].value);
            pie2.a("value2", repData.data1[1].value);
            }
        }

        // OEE/MTBF/MTTR
        function cut2(repData) {
            if(repData.data != null && repData.data != undefined && repData.data != ''){
            Chart[1].a("xAxis", repData.data.month);
            Chart[1].a("yAxis1", repData.data.one);
            Chart[1].a("yAxis2", repData.data.two_1);
            Chart[1].a("yAxis3", repData.data.two_2);
            Chart[1].a("yAxis4", repData.data.three);
            Chart[1].a("yAxis5", repData.data.four);
            }
        }
        //九厂设备维修/维护情况接口
        function getEQWXXHQKTJ(code, work) {
            lostpie = dataModel.getDataByTag("lostpie");
            function err1() {
                warn[0].s("2d.visible", true);
                lostpie.s("2d.visible", false);
            }
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_FC_REPORT_EQWXXHQKTJ",
                    deptCode: code,
                    workshopCode: work,
                },
                headers: request_headers,
                async: false,
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible === "true") {
                        H[0].a("title", repData.totalTitle);
                        warn[0].s("2d.visible", false);
                        lostpie.s("2d.visible", true);
                        cut1(repData)
                    } else {
                        err1()
                    }
                },
                error: function (error) {
                    err1()
                }
            });
            return repData;
        }
        //设备故障停台数接口   
        function getEQGZTTSTJ(code) {
            function err2() {
                warn[1].s("2d.visible", true);
                Chart[0].s("2d.visible", false);
            }
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_FC_REPORT_EQGZTTSTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible === "true") {
                        H[1].a("title", repData.totalTitle);
                        warn[1].s("2d.visible", false);
                        Chart[0].s("2d.visible", true);
                        Chart[0].a("xAxis", repData.data.month);
                        Chart[0].a("yAxis1", repData.data.one);
                        Chart[0].a("yAxis2", repData.data.two);
                        // Chart[0].a("yAxis3", repData.data.two_2);
                        Chart[0].a("yAxis3", repData.data.three);
                        Chart[0].a("yAxis4", repData.data.four);
                    } else {
                        err2()
                    }
                },
                error: function (error) {
                    err2()
                }
            });
            return repData
        }
        //设备OEE/MTBF/MTTR接口
        function getEQOEEMTBFRTJ(code, device) {
            let lostChart = dataModel.getDataByTag("lostChart");
            function err3() {
                warn[2].s("2d.visible", true);
                lostChart.s("2d.visible", false);
            }
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_FC_REPORT_EQOEEMTBFRTJ",
                    deptCode: code,
                    deviceCode: device,
                },
                headers: request_headers,
                async: false,
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible === "true") {
                        H[2].a("title", repData.totalTitle);
                        warn[2].s("2d.visible", false);
                        lostChart.s("2d.visible", true);
                        cut2(repData)
                    } else {
                        err3()
                    }
                },
                error: function (error) {
                    err3()
                }
            });
            return repData
        }
        //设备维修成本接口
        function getEQWXCBTJ(code) {
            const shebei = dataModel.getDataByTag("shebei");
            const text = dataModel.getDataByTag("text");
            var led = [];
            for (let i = 1; i < 5; i++) {
                led.push(dataModel.getDataByTag("led" + i))
            }
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_FC_REPORT_EQWXCBTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible === "true") {
                        H[3].a("title", repData.totalTitle);
                        text.s("text", repData.title);
                        warn[3].s("2d.visible", false);
                        shebei.s("2d.visible", true);
                        led[0].a("number1", repData.data.feiyong[0]);
                        led[0].a("number2", repData.data.feiyong[1]);
                        led[0].a("number3", repData.data.feiyong[2]);
                        led[0].a("number4", repData.data.feiyong[3]);
                        led[0].a("number5", repData.data.feiyong[4]);
                        led[1].a("number1", repData.data.zhanbi[0]);
                        led[1].a("number2", repData.data.zhanbi[1]);
                        led[1].a("number3", repData.data.zhanbi[2]);
                        led[1].a("number4", repData.data.zhanbi[3]);
                        led[1].a("number5", repData.data.zhanbi[4]);
                        led[3].a("number", repData.number)
                    } else {
                        warn[3].s("2d.visible", true);
                        shebei.s("2d.visible", false);
                    }
                },
                error: function (error) {
                    warn[3].s("2d.visible", true);
                    shebei.s("2d.visible", false);
                }
            });
            return repData
        }
        //设备故障率接口
        function getEQGZLTJ(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_FC_REPORT_EQGZLTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible === "true") {
                        H[4].a("title", repData.totalTitle);
                        warn[4].s("2d.visible", false);
                        Chart[2].s("2d.visible", true);
                        Chart[2].a("xdata", repData.data.xdata);
                        Chart[2].a("bar", repData.data.guzhanglv);
                        Chart[2].a("line", repData.data.biaozhun);
                    } else {
                        warn[4].s("2d.visible", true);
                        Chart[2].s("2d.visible", false);
                    }
                },
                error: function (error) {
                    warn[4].s("2d.visible", true);
                    Chart[2].s("2d.visible", false);
                }
            });
            return repData
        }
        //吨平报修统计接口
        function getEQDPNHTJ(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_FC_REPORT_EQDPNHTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        H[5].a("title", repData.totalTitle);
                        warn[5].s("2d.visible", false);
                        Chart[3].s("2d.visible", true);
                        if (repData.data.xdata != "") {
                            Chart[3].a("xdata", repData.data.xdata);
                        }
                        if (repData.data.xdata != "") {
                            Chart[3].a("bar", repData.data.dunpingbaoxiu);
                        }
                        if (repData.data.xdata != "") {
                            Chart[3].a("line", repData.data.biaozhun);
                        }
                        if (repData.data.xdata != "") {
                            Chart[3].a("line1", repData.data.chanliang);
                        }
                        if (repData.data.xdata != "") {
                            Chart[3].a("line2", repData.data.baoxiucishu);
                        }

                    } else {
                        warn[5].s("2d.visible", true);
                        Chart[3].s("2d.visible", false);
                    }
                },
                error: function (error) {
                    warn[5].s("2d.visible", true);
                    Chart[3].s("2d.visible", false);
                }
            });
            return repData;
        }
        //中间3车间
        function getMAP(code) {
            let text11 = dataModel.getDataByTag("text1-1");
            let text12 = dataModel.getDataByTag("text1-2");
            let text21 = dataModel.getDataByTag("text2-1");
            let text22 = dataModel.getDataByTag("text2-2");
            let text3 = dataModel.getDataByTag("text3");
            let text4 = dataModel.getDataByTag("text4");
            let work11 = dataModel.getDataByTag("work1-1");
            let work12 = dataModel.getDataByTag("work1-2");
            const work21 = dataModel.getDataByTag("work2-1");
            const work22 = dataModel.getDataByTag("work2-2");
            const work3 = dataModel.getDataByTag("work3");
            const work4 = dataModel.getDataByTag("work4");
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_ZZ_FC_MAP",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_EQ_ZZ_FC_MAP.visible === "true") {
                        work11.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        work12.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        work21.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        work22.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        work3.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        work4.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        text11.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        text12.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        text21.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        text22.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        text3.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        text4.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                    }
                },
                error: function (error) {
                }
            });
            return repData;
        }
        //返回按钮接口
        function getRETURN(code) {
            const backButton = dataModel.getDataByTag("backButton");
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_FC_BUTTON_RETURN",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_EQ_FC_BUTTON_RETURN.visible === "true") {
                        backButton.a("url", repData.HT_EQ_FC_BUTTON_RETURN.data.url);
                        backButton.s("2d.visible", repData.HT_EQ_FC_BUTTON_RETURN.visible);
                    }
                },
                error: function (error) {
                }
            });
            return repData;
        }
    </script>
</head>

<body onload='setTimeout(init, 300)'>
</body>

</html>